<!--
 * @Date: 2022-04-10 13:25:43
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-08-05 09:07:17
 * @FilePath: \imitation-microblog-vue\src\views\weiboHome\index.vue
 * @Description: 微博内容首页
-->
<template>
  <div class="container">
    <!-- <div v-if="isLogin"> -->
    <create-wei-bo> </create-wei-bo>
    <!-- </div> -->
  </div>
</template>
<script lang="ts" setup>
import { computed, getCurrentInstance, onMounted, ref } from "vue";
import { useStore } from "vuex";
import createWeiBo from "../../components/createWeiBo/index.vue";
import {
  FanslistType,
  followListType,
} from "../../components/createWeiBo/types";
const { $api } = getCurrentInstance()!.appContext.config.globalProperties!;
const store = useStore();
let isLogin = computed(() => store.state.isLogin);
//粉丝列表
let fansList = ref<FanslistType>({});
// 关注列表
let followingList = ref<followListType>({});
//获取粉丝列表
const getFollowerList = async (id: number) => {
  let res = await $api.user.reqFollowUserList(id);
  // console.log("粉丝数据是", res.data);
  if (res.code == 200) {
    fansList.value = res.data;
    // sessionStorage.setItem("fansData", res.data);
    store.commit("updateFansData", res.data);
  }
};
//获取关注列表
const getFollowingList = async (id: number) => {
  let res = await $api.user.reqFollowingList(id);
  // console.log("关注数据是", res.data);
  if (res.code == 200) {
    followingList.value = res.data;
    store.commit("updateFollowingData", res.data);
  }
};
//获取用户信息
const getUserInfo = async () => {
  let res = await $api.user.reqUserInfo();
  if (res.code == 200) {
    // sessionStorage.removeItem("vuex");
    store.commit("updateLoginStatus", true);
    store.commit("updateUserInfo", res.data);
    localStorage.setItem("isLogin", "1");
  } else {
    localStorage.removeItem("isLogin");
    sessionStorage.removeItem("vuex");
  }
};
//获取@我的数量
const getAtMeCount = async () => {
  let res = await $api.user.reqAtMeCount();
  if (res.code == 200) {
    // console.log(res.data.count, "@wode");
    store.commit("updateAtMeCount", res.data.count);
  }
};
//获取@我的评论回复列表
const getAtMeReplyList = async () => {
  let res = await $api.user.reqAtMeReplyList(1);
  if (res.code == 200) {
    store.commit("updateAtMeReplyList", res.data.replyList);
    store.commit("updateReplyCount", res.data.count);
  }
};
//获取@我的博客列表
const getAtMeBlogList = async () => {
  let res = await $api.user.reqAtMeBlogList();
  if (res.code == 200) {
    store.commit("updateAtMeBlogList", res.data.blogList);
    store.commit("updateAtBlogCount", res.data.count);
  }
};
onMounted(async () => {
  // console.log("zuida挂载");
  await getUserInfo();
  getAtMeCount();
  getAtMeReplyList();
  getAtMeBlogList();
  getFollowerList(store.state.userInfos.id);
  getFollowingList(store.state.userInfos.id);
});
</script>
<style lang="less" scoped>
.container {
  background-color: transparent;
}
</style>
